package com.thwj.common.utils;

import java.math.BigDecimal;

public class DistanceUtil {

    public static String getDistanceString(Double distance){
        if(distance == null) {
            return null;
        }
        if(distance < 10D) {
            return "10m";
        }
        if (distance > 10D && distance <= 1000D) {
            return distance.intValue() + "m";
        }
        if (distance > 1000D && distance <= 500 * 1000D) {
            return new BigDecimal(distance / 1000).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue() + "km";
        }
        if (distance > 500 * 1000D) {
            return ">500km";
        }
        if (distance == Integer.MAX_VALUE) {
            return "未定位";
        }
        return distance.toString();
    }

    public static void main(String[] args) {
        System.out.println(getDistanceString(1.5678));
        System.out.println(getDistanceString(156.78));
        System.out.println(getDistanceString(1567.85678));
        System.out.println(getDistanceString(1567.8890));
        System.out.println(getDistanceString(100000567.8890));
    }
}
